﻿using System;
using System.Windows;
using System.Windows.Navigation;
using Redbrick.Silverlight.Common;
using Moria.Common.Model;
using Moria.Common;

namespace Moria.Silverlight.Views
{
    public partial class GameBoard : MoriaPage
    {
        private static Lazy<Uri> myUri = new Lazy<Uri>(() => new Uri("/GameBoard.xaml", UriKind.Relative));

        public GameBoard()
        {
            if (Misc.IsDesignTime(this)) 
            {
                this.DataContext = new TheGame();
            }
            InitializeComponent();
            this.Loaded += new RoutedEventHandler(this.PageLoaded);
        }

        void PageLoaded(object sender, RoutedEventArgs e)
        {
            this.Moria.SaveGameCommand.CanExecuteHandler = (p) => true;
            this.Moria.SaveGameCommand.Executed += new EventHandler<Redbrick.Silverlight.CommandArgs>(SaveGameCommand_Executed);
            this.Moria.GameSaved += new EventHandler<EventArgs>(GameSaved);
        }

        void GameSaved(object sender, EventArgs e)
        {
            MessageBox.Show( string.Format("saved game: {0}",this.Moria.Player.name));
        }

        void SaveGameCommand_Executed(object sender, Redbrick.Silverlight.CommandArgs e)
        {
            this.NavigationService.Navigate(Home.Uri);  // todo: change this to a "game saved" page
        }

        // Executes when the user navigates to this page.
        protected override void OnNavigatedTo(NavigationEventArgs e)
        {
            base.OnNavigatedTo(e);
        }
        public static Uri Uri { get { return myUri.Value; } }

    }
}
